package com.example.goodrubish.Garbage;

import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import androidx.appcompat.app.AppCompatActivity;

import com.example.goodrubish.R;


public class SortActivity extends AppCompatActivity {
    private  LinearLayout notificationContainer1,notificationContainer2,notificationContainer3,notificationContainer4;
    private RelativeLayout fabContainer;
    private float initialX;
    private float initialY;
    private float initialTouchX;
    private float initialTouchY;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sort);

        fabContainer = findViewById(R.id.fab_container);
        notificationContainer1 = findViewById(R.id.notification_container1);
        notificationContainer2 = findViewById(R.id.notification_container2);
        notificationContainer3 = findViewById(R.id.notification_container3);
        notificationContainer4 = findViewById(R.id.notification_container4);

        // 设置点击事件
        notificationContainer1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 处理点击事件
                startActivity(new Intent(SortActivity.this, RecycleActivity.class));

            }
        });
        // 设置点击事件
        notificationContainer2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 处理点击事件
                startActivity(new Intent(SortActivity.this, HarmwasteActivity.class));

            }
        });
        // 设置点击事件
        notificationContainer3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 处理点击事件
                startActivity(new Intent(SortActivity.this, KitchenActivity.class));

            }
        });
        // 设置点击事件
        notificationContainer4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 处理点击事件
                startActivity(new Intent(SortActivity.this, OtherActivity.class));


            }
        });
        fabContainer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 处理点击事件
                startActivity(new Intent(SortActivity.this, QuizActivity.class));
            }
        });

        fabContainer.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent event) {
                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        // 记录初始位置
                        initialX = fabContainer.getX();
                        initialY = fabContainer.getY();
                        initialTouchX = event.getRawX();
                        initialTouchY = event.getRawY();
                        return false; // 返回false表示事件已被处理

                    case MotionEvent.ACTION_MOVE:
                        // 计算新的位置
                        float newX = initialX + (event.getRawX() - initialTouchX);
                        float newY = initialY + (event.getRawY() - initialTouchY);

                        // 更新容器的位置
                        fabContainer.setX(newX);
                        fabContainer.setY(newY);
                        return true; // 返回true表示事件已被处理

                    case MotionEvent.ACTION_UP:
                        // 可以在这里处理释放时的逻辑
                        return false; // 返回true表示事件已被处理
                }
                return false;
            }
        });

    }
}